package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Publish.HomeWorkAndExam;

import android.os.Bundle;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;

import java.util.Objects;

public class CreateHomeFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;
    View view;
    LinearLayout ll_single,ll_multiple,ll_judge,ll_FillBlank,ll_shortAnswer,ll_TextImport;
    ImageView iv_back;
    TextView tv_select,tv_head,tv_title,tv_deadline;

    public CreateHomeFragment() {
    }

    public static CreateHomeFragment newInstance(String param1, String param2) {
        CreateHomeFragment fragment = new CreateHomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.course_create_home_fragment, container, false);
        ll_judge = view.findViewById(R.id.ll_judge);
        ll_multiple = view.findViewById(R.id.ll_multiple);
        ll_FillBlank = view.findViewById(R.id.ll_FillBlank);
        ll_single = view.findViewById(R.id.ll_single);
        ll_shortAnswer = view.findViewById(R.id.ll_ShortAnswer);
        ll_TextImport = view.findViewById(R.id.ll_TextImport);
        iv_back = view.findViewById(R.id.iv_back);
        tv_select = view.findViewById(R.id.tv_select);

        InitUI();
        //选择提交者点击监听
        tv_select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_createHomeFragment_to_selectStudentFragment);
            }
        });

        //单选题点击监听
        ll_single.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                CreateHomeFragmentDirections.ActionCreateHomeFragmentToSingleFragment action = CreateHomeFragmentDirections.actionCreateHomeFragmentToSingleFragment();
                action.setLabel("single");
                navController.navigate(action);
            }
        });

        ll_multiple.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                CreateHomeFragmentDirections.ActionCreateHomeFragmentToSingleFragment action = CreateHomeFragmentDirections.actionCreateHomeFragmentToSingleFragment();
                action.setLabel("multiple");
                navController.navigate(action);
            }
        });

        //判断题点击监听
        ll_judge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_createHomeFragment_to_judgeFragment);
            }
        });

        //简答题点击监听
        ll_shortAnswer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_createHomeFragment_to_shortAnswerFragment);
            }
        });

        //填空题点击监听
        ll_FillBlank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_createHomeFragment_to_fillBlankFragment);
            }
        });

        //文本导入点击监听
        ll_TextImport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_createHomeFragment_to_textImportFragment);
            }
        });

        //返回点击监听
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigateUp();
            }
        });
        return view;
    }

    private void InitUI() {
        tv_title = view.findViewById(R.id.tv_title);
        tv_head = view.findViewById(R.id.tv_head);
        tv_deadline = view.findViewById(R.id.tv_deadline);
        assert getArguments() != null;
        String ExamOrHomeWork = getArguments().getString("label");
        //检测
        if (!Objects.equals(ExamOrHomeWork, "error") && Objects.equals(ExamOrHomeWork, "HomeWork")) {
            tv_head.setText("创建作业");
            tv_title.setText("作业标题 :");
            tv_deadline.setText("提交作业截止时间");
        }else if(Objects.equals(ExamOrHomeWork, "exam")) {
            tv_head.setText("创建考试");
            tv_title.setText("考试标题 :");
            tv_deadline.setText("考试截止时间");
        } else if (Objects.equals(ExamOrHomeWork, "task")) {
            tv_head.setText("创建任务");
            tv_title.setText("任务标题 :");
            tv_deadline.setText("任务截止时间");
        }
    }
}